import 'package:distribution_mall_flutter/firebase_options_fat.dart';
import 'package:distribution_mall_flutter/firebase_options_pro.dart';
import 'package:distribution_mall_flutter/utils/analytics.dart';
import 'package:distribution_mall_flutter/utils/utils.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';

class FirebaseUtils {
  static Future<void> init() async {
    final bool isFat = Utils.getEnvIsFat();
    await Firebase.initializeApp(
      // options: ProFirebaseOptions.currentPlatform,
      name: isFat ? 'fat' : '[DEFAULT]',
      options: isFat
          ? FatFirebaseOptions.currentPlatform
          : ProFirebaseOptions.currentPlatform,
    );

    // await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
    // await Firebase.initializeApp(
    //   name: 'pro',
    //   options: ProFirebaseOptions.currentPlatform,
    // );
    // Pass all uncaught "fatal" errors from the framework to Crashlytics
    if (!kIsWeb && !isFat) {
      FlutterError.onError = (errorDetails) {
        FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
      };
      // Pass all uncaught asynchronous errors that aren't handled by the Flutter framework to Crashlytics
      PlatformDispatcher.instance.onError = (error, stack) {
        FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
        return true;
      };
    }
    // 设置 firebase分析 默认参数
    EPAnalytics.initDefaultParams();
  }
}
